package com.example.sys2.controller;


import com.example.sys2.common.result.ResultUtils;
import com.example.sys2.entity.Type;
import com.example.sys2.service.ITypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;



/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chenyueyang
 * @since 2023-09-21
 */
@RestController
@RequestMapping("/type")
public class TypeController {
    @Autowired
    ITypeService service;


    @GetMapping("/getTypeList")
    public Object getTypeList(){
        return ResultUtils.returnSuccessLayui(service.list(),service.list().size());
    }
    @PostMapping("/addType")
    public Object addType(Type type){
        if(service.save(type)){
            return ResultUtils.returnSuccess();
        }else{
            return ResultUtils.returnFail();
        }

    }

    @PostMapping("/updateType")
    public Object updateType(Type type){
        if(service.updateById(type)){
            return ResultUtils.returnSuccess();
        }else{
            return ResultUtils.returnFail();
        }

    }

    @PostMapping("/deleteType")
    public Object deleteType(Type type){
        if(service.removeById(type)){
            return ResultUtils.returnSuccess();
        }else{
            return ResultUtils.returnFail();
        }

    }
}

